package com.room.room.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import com.project.utils.PageUtils;
import com.project.utils.R;
import com.room.room.entity.HouseModeEntity;
import com.room.room.entity.HousePayEntity;
import com.room.room.util.OssUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.room.room.entity.HouseNewsEntity;
import com.room.room.service.HouseNewsService;
import org.springframework.web.multipart.MultipartFile;


/**
 * 
 *
 * @author brh
 * @email sunlightcs@gmail.com
 * @date 2022-03-23 16:10:46
 */
@RestController
@RequestMapping("room/housenews")
public class HouseNewsController {
    @Autowired
    private HouseNewsService houseNewsService;

    @Autowired
    private OssUtils ossUtils;

    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = houseNewsService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{newsId}")
    public R info(@PathVariable("newsId") Integer newsId){
		HouseNewsEntity houseNews = houseNewsService.getById(newsId);

        return R.ok().put("houseNews", houseNews);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody HouseNewsEntity houseNews){
		houseNewsService.save(houseNews);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody HouseNewsEntity houseNews){
		houseNewsService.updateById(houseNews);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Integer[] newsIds){
		houseNewsService.removeByIds(Arrays.asList(newsIds));

        return R.ok();
    }

    //上传图片
    @RequestMapping("/upload")
    public R upload(MultipartFile file){
        R r= ossUtils.uploadFile(file);
        return r;
    }

    //支付下拉
    @RequestMapping("/payXl")
    public R payXl(){
        List<HousePayEntity> payList = houseNewsService.payXl();
        return R.ok().put("payType",payList);
    }

    //房型下拉
    @RequestMapping("/roomXl")
    public R roomXl(){
        List<HouseModeEntity> roomList = houseNewsService.RoomXl();
        return R.ok().put("RoomType",roomList);
    }

}
